// /////////////////////////////////////////////////////////////////////////////
//
// Name:            asHasEvents.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Binds the HasEvents class to AngelScript
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __ASHASEVENTS_H__
#define __ASHASEVENTS_H__

// Include files
#include "../../dependencies.h"

#ifdef __COMPILE_WITH_ANGELSCRIPT__

#include "../../core/HasEvents.h"
#include "../ScriptHelper.h"


//! Wrapper function to allow script-side classes to connect event signals.
//! @note For internal use only!
extern bool connectEventSignal(const std::string &slotName, asIScriptObject *object,
                               const std::string &function, HasEvents *container);

//! Wrapper function to allow script-side classes to disconnect event signals.
//! @note For internal use only!
extern void disconnectEventSignal(const std::string &slotName, asIScriptObject *object,
                                  const std::string &function, HasEvents *container);


//! Binds the base behaviours and methods of the HasEvents class to the given class in
//! AngelScript.
template<typename T>
void bindHasEventsBase(asIScriptEngine *engine, const char *type)
{
    // Forward declaration.
    int r;
    std::string sType = type;

    // Bind common class functions.
    r = engine->RegisterObjectMethod(type, "bool createEventSlot(const string &in)",
									asMETHODPR(T, createEventSlot, (const std::string&), bool), asCALL_THISCALL); assert(r >= 0);

    r = engine->RegisterObjectMethod(type, "bool connectEventSignal(const string &in, IHasSlots@, " \
                                     "const string &in)", asFUNCTION(connectEventSignal), asCALL_CDECL_OBJLAST);
                                     assert(r >= 0);
    r = engine->RegisterObjectMethod(type, "bool disconnectEventSignal(const string &in, IHasSlots@, " \
                                     "const string &in)", asFUNCTION(disconnectEventSignal), asCALL_CDECL_OBJLAST);
                                     assert(r>= 0);

	r = engine->RegisterObjectMethod(type, "bool emitEvent(const string &in)",
									asMETHODPR(T, emitEvent, (const std::string&, void*), bool), asCALL_THISCALL); 
									assert(r >= 0);

    r = engine->RegisterObjectMethod(type, "bool emitEvent(const string &in, ? &in)",
                                    asMETHODPR(T, emitEvent, (const std::string&, void*), bool), asCALL_THISCALL); 
									assert(r >= 0);

    r = engine->RegisterObjectMethod(type, "void removeEventSlots()",
                                     asMETHOD(T, removeEventSlots), asCALL_THISCALL); 
									assert(r >= 0);

	r =	engine->RegisterObjectMethod(type, "bool removeEventSlot(const string &in)",
									 asMETHODPR(T, removeEventSlot, (const std::string&), bool), asCALL_THISCALL);
									assert(r >= 0);
}

#endif // __COMPILE_WITH_ANGELSCRIPT__

#endif
